﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;

/// <summary>
/// Summary description for QLHoa
/// </summary>
public class QLHoa
{
    DBConnection db = new DBConnection();
	public QLHoa()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public DataTable Load_QLHoa()
    {
        string sql = "select loaihoa.maloai,tenloai,hoa.mahoa,tenhoa,nguongoc,ynghia,giahoa,hinhanh,soluong from loaihoa,hoa,CTloaihoa where CTloaihoa.maloai=loaihoa.maloai and hoa.mahoa=ctloaihoa.mahoa";
        return db.Get_data(sql);
    }
    public string Insert_Hoa(string ten,string nguon,string ynghia,string gia,string hinhanh)
    {
        string sql = "insert into hoa(tenhoa,nguongoc,ynghia,giahoa,hinhanh) values(@ten,@nguon,@ynghia,@gia,@hinhanh)";
        SqlParameter p1 = new SqlParameter("@ten", ten);
        SqlParameter p2 = new SqlParameter("@nguon", nguon);
        SqlParameter p3 = new SqlParameter("@ynghia", ynghia);
        SqlParameter p4 = new SqlParameter("@gia", gia);
        SqlParameter p5 = new SqlParameter("@hinhanh", hinhanh);
        if(db.Get_data(sql, p1, p2, p3, p4, p5)!=null)
        {
            string sql1 = "SELECT MAX(mahoa) FROM hoa";
            object kq = db.LayDuLieu(sql1);
            return kq.ToString();
        }
        return "";
    }
    public void Update_Hoa(string ma,string ten, string nguon, string ynghia, string gia, string hinhanh)
    {
        string sql = "update hoa set tenhoa=@ten,nguongoc=@nguongoc,ynghia=@ynghia,giahoa=@giahoa,hinhanh=@hinhanh where mahoa=@mahoa";
        SqlParameter p1 = new SqlParameter("@mahoa", ma);
        SqlParameter p2 = new SqlParameter("@ten", ten);
        SqlParameter p3 = new SqlParameter("@nguongoc", nguon);
        SqlParameter p4 = new SqlParameter("@ynghia", ynghia);
        SqlParameter p5 = new SqlParameter("@giahoa", gia);
        SqlParameter p6 = new SqlParameter("@hinhanh", hinhanh);
        db.thuchienlenh(sql, p1, p2, p3, p4, p5, p6);
    }
    public DataTable Delete_Hoa(string mahoa)
    {
        string sql = "delete from hoa where mahoa=@mahoa";
        SqlParameter p1 = new SqlParameter("@mahoa",mahoa);
        return db.Get_data(sql, p1);
    }


    public void Insert_CTLoaiHoa(string maloaihoa,string mahoa,int SL)
    {
        string sql = "insert into ctloaihoa values (@maloaihoa,@mahoa,@SL)";
        SqlParameter p1 = new SqlParameter("@maloaihoa",maloaihoa);
        SqlParameter p2 = new SqlParameter("@mahoa", mahoa);
        SqlParameter p3 = new SqlParameter("@SL", SL);
        db.thuchienlenh(sql, p1, p2, p3);
    }
    public void Update_CTLoaiHoa(string maloai,string mahoa,string sl)
    {
        string sql = "update ctloaihoa set maloai=@maloai,soluong=@sl where mahoa=@mahoa";
        SqlParameter p1=new SqlParameter("@maloai",maloai);
        SqlParameter p2=new SqlParameter("@mahoa",mahoa);
        SqlParameter p3=new SqlParameter("@sl",sl);
        db.Get_data(sql, p1, p2, p3);
    }
    public DataTable Delete_CTLoaiHoa(string mahoa)
    {
        string sql = "delete from ctloaihoa where ctloaihoa.mahoa=@mahoa";
        SqlParameter p1=new SqlParameter("@mahoa",mahoa);
        return db.Get_data(sql, p1);
    }
}
